package com.cx.service.wjr.impl;

import com.cx.mapper.PageMapper;
import com.cx.mapper.UserMapper;
import com.cx.pojo.Page;
import com.cx.pojo.PageExample;
import com.cx.pojo.User;
import com.cx.pojo.UserExample;
import com.cx.pojo.wjr.UserPage;
import com.cx.service.wjr.UserService;

import com.cx.util.wjr.PageUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;
    @Autowired
    PageMapper pageMapper;



    @Transactional
    public int addUserPage(UserPage userPage){
        System.out.println("impl执行了");
        userPage.setSendId((int) System.currentTimeMillis()%1000000);
        userPage.setReceiveId((int) System.currentTimeMillis()%1000000);
        int count1 =  pageMapper.insertUserPageSend(userPage);
        int count2 = pageMapper.insertUserPageReceive(userPage);
        int count3 = pageMapper.insertUserPagePage(userPage);
        return count1+count2+count3;
    }

    @Override
    public List<Page> selectByPageNum(PageExample pageExample) {
        return pageMapper.selectByExample(pageExample);
    }

    @Override
    public List<Page> selectByPagePhone(PageExample pageExample) {
        return null;
    }

    public List<User> select(UserExample user) {
        return userMapper.selectByExample(user);
    }

    public PageInfo<User> listPage(UserExample b, Integer pageNum, Integer pageSize) { return PageHelper.startPage(pageNum, pageSize).doSelectPageInfo(() -> { userMapper.selectByExample(b); }); }


    public User selectByName(User user) {
        return null;
    }

    public int addCourier(User user) {
        return userMapper.insert(user);
    }

    //public PageInfo<UserExample> listPage(UserExample user, int pageNum, int pageSize) { return PageHelper.startPage(pageNum, pageSize).doSelectPageInfo(() -> { userMapper.selectByExample(user); }); }


    @Override
    public List<User> selectByExample(UserExample userExample) {
        return userMapper.selectByExample(userExample);
    }

    @Override
    public int delete(UserExample userExample) {
        return userMapper.deleteByExample(userExample);
    }

    @Override
    public int update(@Param("record") User record, @Param("example") UserExample example) {
        return userMapper.updateByExampleSelective(record,example);
    }
}
